package
{
	import flash.display.MovieClip;

	public class TileMapCell
	{
		public var CTYPE:Number;
		public var ID:Number;
		//
		public var i:Number;
		public var j:Number;
		//
		public var nU:TileMapCell;
		public var nD:TileMapCell;
		public var nL:TileMapCell;
		public var nR:TileMapCell;
		//
		public var eU:int;
		public var eD:int;
		public var eL:int;
		public var eR:int;
		//
		public var gx:Number;
		public var gy:Number;
		public var d:Number;
		public var next;
		public var prev;
		public var objcounter:Number;
		public var pos:Vector2;
		public var xw:Number;
		public var yw:Number;
		public var minx:Number;
		public var maxx:Number;
		public var miny:Number;
		public var maxy:Number;
		//
		public var signx:Number;
		public var signy:Number;
		public var sx:Number;
		public var sy:Number;
		public var mc:MovieClip;

		// i列 j行 x y中心位置 xw yw宽高
		public function TileMapCell(i:Number, j:Number, x:Number, y:Number, xw:Number, yw:Number)
		{
			this.CTYPE = TileMapCell.CTYPE_EMPTY;
			this.ID = TileMapCell.TID_EMPTY;
			//
			this.i = i;
			this.j = j;
			//
			this.nU = null;
			this.nD = null;
			this.nL = null;
			this.nR = null;
			//
			this.eU = TileMapCell.EID_OFF;
			this.eD = TileMapCell.EID_OFF;
			this.eL = TileMapCell.EID_OFF;
			this.eR = TileMapCell.EID_OFF;
			//
			this.gx = 0;
			this.gy = Main.getInstance().GRAV;
			this.d = Main.getInstance().DRAG;
			this.next = null;
			this.prev = null;
			this.objcounter = 0;
			this.pos = new Vector2(x, y);
			this.xw = xw;
			this.yw = yw;
			//
			this.minx = this.pos.x - this.xw;
			this.maxx = this.pos.x + this.xw;
			this.miny = this.pos.y - this.yw;
			this.maxy = this.pos.y + this.yw;
			this.signx = 0;
			this.signy = 0;
			this.sx = 0;
			this.sy = 0;
			var _local2 = false;
			if (!_local2)
			{
				this.mc = Main.getInstance().gfx.CreateSprite("tileMC", NinjaGraphicsSystem.LAYER_TILES);
				this.mc.gotoAndStop(1);
				this.mc.scaleX = this.xw * 2;
				this.mc.scaleY = this.yw * 2;
				this.mc.x = this.pos.x;
				this.mc.y = this.pos.y;
				// var _local3 = new Color(this.mc);
				// _local3.setRGB(0x797988);
			}
			else
			{
				this.mc = Main.getInstance().gfx.CreateSprite("tileMC2", NinjaGraphicsSystem.LAYER_TILES2);
				this.mc.gotoAndStop(1);
				this.mc.scaleX = this.xw * 2;
				this.mc.scaleY = this.yw * 2;
				this.mc.x = this.pos.x;
				this.mc.y = this.pos.y;
			}
		}

		// 小类
		public static const TID_EMPTY:int = 0;
		public static const TID_FULL:int = 1;
		public static const TID_45DEGpn:int = 2;
		public static const TID_45DEGnn:int = 3;
		public static const TID_45DEGnp:int = 4;
		public static const TID_45DEGpp:int = 5;
		public static const TID_CONCAVEpn:int = 6;
		public static const TID_CONCAVEnn:int = 7;
		public static const TID_CONCAVEnp:int = 8;
		public static const TID_CONCAVEpp:int = 9;
		public static const TID_CONVEXpn:int = 10;
		public static const TID_CONVEXnn:int = 11;
		public static const TID_CONVEXnp:int = 12;
		public static const TID_CONVEXpp:int = 13;
		public static const TID_22DEGpnS:int = 14;
		public static const TID_22DEGnnS:int = 15;
		public static const TID_22DEGnpS:int = 16;
		public static const TID_22DEGppS:int = 17;
		public static const TID_22DEGpnB:int = 18;
		public static const TID_22DEGnnB:int = 19;
		public static const TID_22DEGnpB:int = 20;
		public static const TID_22DEGppB:int = 21;
		public static const TID_67DEGpnS:int = 22;
		public static const TID_67DEGnnS:int = 23;
		public static const TID_67DEGnpS:int = 24;
		public static const TID_67DEGppS:int = 25;
		public static const TID_67DEGpnB:int = 26;
		public static const TID_67DEGnnB:int = 27;
		public static const TID_67DEGnpB:int = 28;
		public static const TID_67DEGppB:int = 29;
		public static const TID_HALFd:int = 30;
		public static const TID_HALFr:int = 31;
		public static const TID_HALFu:int = 32;
		public static const TID_HALFl:int = 33;
		// 大类
		public static const CTYPE_EMPTY:int = 0;
		public static const CTYPE_FULL:int = 1;
		public static const CTYPE_45DEG:int = 2;
		public static const CTYPE_CONCAVE:int = 6;
		public static const CTYPE_CONVEX:int = 10;
		public static const CTYPE_22DEGs:int = 14;
		public static const CTYPE_22DEGb:int = 18;
		public static const CTYPE_67DEGs:int = 22;
		public static const CTYPE_67DEGb:int = 26;
		public static const CTYPE_HALF:int = 30;
		//
		public static const EID_OFF:int = 0;
		public static const EID_INTERESTING:int = 1;
		public static const EID_SOLID:int = 2;

		// up
		public function LinkU(t:TileMapCell):void
		{
			this.nU = t;
		}

		// down
		public function LinkD(t:TileMapCell):void
		{
			this.nD = t;
		}

		// left
		public function LinkL(t:TileMapCell):void
		{
			this.nL = t;
		}

		// right
		public function LinkR(t:TileMapCell):void
		{
			this.nR = t;
		}

		public function ToString():String
		{
			return "(" + this.i + "," + this.j + ")";
		}

		public function Draw():void
		{
			this.mc.gotoAndStop(this.ID + 1);
		}

		public function SetState(ID:int):void
		{
			if (ID == TileMapCell.TID_EMPTY)
			{
				this.Clear();
			}
			else
			{
				this.ID = ID;
				this.UpdateType();
				this.UpdateEdges();
				this.UpdateNeighbors();
			}
		}

		public function Clear():void
		{
			this.ID = TileMapCell.TID_EMPTY;
			this.UpdateType();
			this.UpdateEdges();
			this.UpdateNeighbors();
			this.Draw();
		}

		public function UpdateNeighbors():void
		{
			if (this.nU != null)
			{
				this.nU.UpdateEdges();
			}
			if (this.nD != null)
			{
				this.nD.UpdateEdges();
			}
			if (this.nL != null)
			{
				this.nL.UpdateEdges();
			}
			if (this.nR != null)
			{
				this.nR.UpdateEdges();
			}
		}

		// 更新大类、方向、法线
		public function UpdateType():void
		{
			var SQRT5:Number = 2.23606797749979;
			switch(this.ID)
			{
				case TileMapCell.TID_EMPTY:
					// 0
					this.CTYPE = TileMapCell.CTYPE_EMPTY;
					this.signx = 0;
					this.signy = 0;
					this.sx = 0;
					this.sy = 0;
					break;
				case TileMapCell.TID_FULL:
					// 1
					this.CTYPE = TileMapCell.CTYPE_FULL;
					this.signx = 0;
					this.signy = 0;
					this.sx = 0;
					this.sy = 0;
					break;
				case TileMapCell.TID_45DEGpn:
					// 2
					this.CTYPE = TileMapCell.CTYPE_45DEG;
					this.signx = 1;
					// 方向
					this.signy = -1;
					this.sx = this.signx / Math.SQRT2;
					// 法线
					this.sy = this.signy / Math.SQRT2;
					break;
				case TileMapCell.TID_45DEGnn:
					// 3
					this.CTYPE = TileMapCell.CTYPE_45DEG;
					this.signx = -1;
					this.signy = -1;
					this.sx = this.signx / Math.SQRT2;
					this.sy = this.signy / Math.SQRT2;
					break;
				case TileMapCell.TID_45DEGnp:
					// 4
					this.CTYPE = TileMapCell.CTYPE_45DEG;
					this.signx = -1;
					this.signy = 1;
					this.sx = this.signx / Math.SQRT2;
					this.sy = this.signy / Math.SQRT2;
					break;
				case TileMapCell.TID_45DEGpp:
					// 5
					this.CTYPE = TileMapCell.CTYPE_45DEG;
					this.signx = 1;
					this.signy = 1;
					this.sx = this.signx / Math.SQRT2;
					this.sy = this.signy / Math.SQRT2;
					break;
				case TileMapCell.TID_CONCAVEpn:
					// 6
					this.CTYPE = TileMapCell.CTYPE_CONCAVE;
					this.signx = 1;
					this.signy = -1;
					this.sx = 0;
					this.sy = 0;
					break;
				case TileMapCell.TID_CONCAVEnn:
					// 7
					this.CTYPE = TileMapCell.CTYPE_CONCAVE;
					this.signx = -1;
					this.signy = -1;
					this.sx = 0;
					this.sy = 0;
					break;
				case TileMapCell.TID_CONCAVEnp:
					// 8
					this.CTYPE = TileMapCell.CTYPE_CONCAVE;
					this.signx = -1;
					this.signy = 1;
					this.sx = 0;
					this.sy = 0;
					break;
				case TileMapCell.TID_CONCAVEpp:
					// 9
					this.CTYPE = TileMapCell.CTYPE_CONCAVE;
					this.signx = 1;
					this.signy = 1;
					this.sx = 0;
					this.sy = 0;
					break;
				case TileMapCell.TID_CONVEXpn:
					// 10
					this.CTYPE = TileMapCell.CTYPE_CONVEX;
					this.signx = 1;
					this.signy = -1;
					this.sx = 0;
					this.sy = 0;
					break;
				case TileMapCell.TID_CONVEXnn:
					// 11
					this.CTYPE = TileMapCell.CTYPE_CONVEX;
					this.signx = -1;
					this.signy = -1;
					this.sx = 0;
					this.sy = 0;
					break;
				case TileMapCell.TID_CONVEXnp:
					// 12
					this.CTYPE = TileMapCell.CTYPE_CONVEX;
					this.signx = -1;
					this.signy = 1;
					this.sx = 0;
					this.sy = 0;
					break;
				case TileMapCell.TID_CONVEXpp:
					// 13
					this.CTYPE = TileMapCell.CTYPE_CONVEX;
					this.signx = 1;
					this.signy = 1;
					this.sx = 0;
					this.sy = 0;
					break;
				case TileMapCell.TID_22DEGpnS:
					// 14
					this.CTYPE = TileMapCell.CTYPE_22DEGs;
					this.signx = 1;
					this.signy = -1;
					this.sx = (this.signx * 1) / SQRT5;
					this.sy = (this.signy * 2) / SQRT5;
					break;
				case TileMapCell.TID_22DEGnnS:
					// 15
					this.CTYPE = TileMapCell.CTYPE_22DEGs;
					this.signx = -1;
					this.signy = -1;
					this.sx = (this.signx * 1) / SQRT5;
					this.sy = (this.signy * 2) / SQRT5;
					break;
				case TileMapCell.TID_22DEGnpS:
					// 16
					this.CTYPE = TileMapCell.CTYPE_22DEGs;
					this.signx = -1;
					this.signy = 1;
					this.sx = (this.signx * 1) / SQRT5;
					this.sy = (this.signy * 2) / SQRT5;
					break;
				case TileMapCell.TID_22DEGppS:
					// 17
					this.CTYPE = TileMapCell.CTYPE_22DEGs;
					this.signx = 1;
					this.signy = 1;
					this.sx = (this.signx * 1) / SQRT5;
					this.sy = (this.signy * 2) / SQRT5;
					break;
				case TileMapCell.TID_22DEGpnB:
					// 18
					this.CTYPE = TileMapCell.CTYPE_22DEGb;
					this.signx = 1;
					this.signy = -1;
					this.sx = (this.signx * 1) / SQRT5;
					this.sy = (this.signy * 2) / SQRT5;
					break;
				case TileMapCell.TID_22DEGnnB:
					// 19
					this.CTYPE = TileMapCell.CTYPE_22DEGb;
					this.signx = -1;
					this.signy = -1;
					this.sx = (this.signx * 1) / SQRT5;
					this.sy = (this.signy * 2) / SQRT5;
					break;
				case TileMapCell.TID_22DEGnpB:
					// 20
					this.CTYPE = TileMapCell.CTYPE_22DEGb;
					this.signx = -1;
					this.signy = 1;
					this.sx = (this.signx * 1) / SQRT5;
					this.sy = (this.signy * 2) / SQRT5;
					break;
				case TileMapCell.TID_22DEGppB:
					// 21
					this.CTYPE = TileMapCell.CTYPE_22DEGb;
					this.signx = 1;
					this.signy = 1;
					this.sx = (this.signx * 1) / SQRT5;
					this.sy = (this.signy * 2) / SQRT5;
					break;
				case TileMapCell.TID_67DEGpnS:
					// 22
					this.CTYPE = TileMapCell.CTYPE_67DEGs;
					this.signx = 1;
					this.signy = -1;
					this.sx = (this.signx * 2) / SQRT5;
					this.sy = (this.signy * 1) / SQRT5;
					break;
				case TileMapCell.TID_67DEGnnS:
					// 23
					this.CTYPE = TileMapCell.CTYPE_67DEGs;
					this.signx = -1;
					this.signy = -1;
					this.sx = (this.signx * 2) / SQRT5;
					this.sy = (this.signy * 1) / SQRT5;
					break;
				case TileMapCell.TID_67DEGnpS:
					// 24
					this.CTYPE = TileMapCell.CTYPE_67DEGs;
					this.signx = -1;
					this.signy = 1;
					this.sx = (this.signx * 2) / SQRT5;
					this.sy = (this.signy * 1) / SQRT5;
					break;
				case TileMapCell.TID_67DEGppS:
					// 25
					this.CTYPE = TileMapCell.CTYPE_67DEGs;
					this.signx = 1;
					this.signy = 1;
					this.sx = (this.signx * 2) / SQRT5;
					this.sy = (this.signy * 1) / SQRT5;
					break;
				case TileMapCell.TID_67DEGpnB:
					// 26
					this.CTYPE = TileMapCell.CTYPE_67DEGb;
					this.signx = 1;
					this.signy = -1;
					this.sx = (this.signx * 2) / SQRT5;
					this.sy = (this.signy * 1) / SQRT5;
					break;
				case TileMapCell.TID_67DEGnnB:
					// 27
					this.CTYPE = TileMapCell.CTYPE_67DEGb;
					this.signx = -1;
					this.signy = -1;
					this.sx = (this.signx * 2) / SQRT5;
					this.sy = (this.signy * 1) / SQRT5;
					break;
				case TileMapCell.TID_67DEGnpB:
					// 28
					this.CTYPE = TileMapCell.CTYPE_67DEGb;
					this.signx = -1;
					this.signy = 1;
					this.sx = (this.signx * 2) / SQRT5;
					this.sy = (this.signy * 1) / SQRT5;
					break;
				case TileMapCell.TID_67DEGppB:
					// 29
					this.CTYPE = TileMapCell.CTYPE_67DEGb;
					this.signx = 1;
					this.signy = 1;
					this.sx = (this.signx * 2) / SQRT5;
					this.sy = (this.signy * 1) / SQRT5;
					break;
				case TileMapCell.TID_HALFd:
					// 30
					this.CTYPE = TileMapCell.CTYPE_HALF;
					this.signx = 0;
					this.signy = -1;
					this.sx = this.signx;
					this.sy = this.signy;
					break;
				case TileMapCell.TID_HALFr:
					// 31
					this.CTYPE = TileMapCell.CTYPE_HALF;
					this.signx = -1;
					this.signy = 0;
					this.sx = this.signx;
					this.sy = this.signy;
					break;
				case TileMapCell.TID_HALFu:
					// 32
					this.CTYPE = TileMapCell.CTYPE_HALF;
					this.signx = 0;
					this.signy = 1;
					this.sx = this.signx;
					this.sy = this.signy;
					break;
				case TileMapCell.TID_HALFl:
					// 33
					this.CTYPE = TileMapCell.CTYPE_HALF;
					this.signx = 1;
					this.signy = 0;
					this.sx = this.signx;
					this.sy = this.signy;
					break;
				default:
					this.CTYPE = TileMapCell.CTYPE_EMPTY;
					this.signx = 0;
					this.signy = 0;
					this.sx = 0;
					this.sy = 0;
					break;
			}
		}

		public function UpdateEdges():void
		{
			// 上
			if (this.ID == TileMapCell.TID_EMPTY)
			{
				if (this.nU.ID == TileMapCell.TID_EMPTY)
				{
					this.eU = TileMapCell.EID_OFF;
				}
				else if (this.nU.ID == TileMapCell.TID_FULL)
				{
					this.eU = TileMapCell.EID_SOLID;
				}
				else if ((((this.nU.signy * -1) <= 0) || (this.nU.ID == TileMapCell.TID_67DEGpnS)) || (this.nU.ID == TileMapCell.TID_67DEGnnS))
				{
					this.eU = TileMapCell.EID_INTERESTING;
				}
				else
				{
					this.eU = TileMapCell.EID_SOLID;
				}
			}
			else if (this.ID == TileMapCell.TID_FULL)
			{
				if (this.nU.ID == TileMapCell.TID_FULL)
				{
					this.eU = TileMapCell.EID_OFF;
				}
				else if (this.nU.ID == TileMapCell.TID_EMPTY)
				{
					this.eU = TileMapCell.EID_OFF;
				}
				else if ((((this.nU.signy * -1) <= 0) || (this.nU.ID == TileMapCell.TID_67DEGpnS)) || (this.nU.ID == TileMapCell.TID_67DEGnnS))
				{
					this.eU = TileMapCell.EID_INTERESTING;
				}
				else
				{
					this.eU = TileMapCell.EID_OFF;
				}
			}
			else if (0 <= (this.signy * -1))
			{
				if (this.nU.ID == TileMapCell.TID_EMPTY)
				{
					this.eU = TileMapCell.EID_OFF;
				}
				else if (this.nU.ID == TileMapCell.TID_FULL)
				{
					this.eU = TileMapCell.EID_SOLID;
				}
				else if ((((this.nU.signy * -1) <= 0) || (this.nU.ID == TileMapCell.TID_67DEGpnS)) || (this.nU.ID == TileMapCell.TID_67DEGnnS))
				{
					this.eU = TileMapCell.EID_INTERESTING;
				}
				else
				{
					this.eU = TileMapCell.EID_SOLID;
				}
			}
			else if ((this.ID == TileMapCell.TID_67DEGppS) || (this.ID == TileMapCell.TID_67DEGnpS))
			{
				if (this.nU.ID == TileMapCell.TID_EMPTY)
				{
					this.eU = TileMapCell.EID_OFF;
				}
				else if (this.nU.ID == TileMapCell.TID_FULL)
				{
					this.eU = TileMapCell.EID_SOLID;
				}
				else if ((((this.nU.signy * -1) <= 0) || (this.nU.ID == TileMapCell.TID_67DEGpnS)) || (this.nU.ID == TileMapCell.TID_67DEGnnS))
				{
					this.eU = TileMapCell.EID_INTERESTING;
				}
				else if ((0 < (this.nU.signy * -1)) || (this.nU.ID == TileMapCell.TID_FULL))
				{
					this.eU = TileMapCell.EID_SOLID;
				}
				else
				{
					this.eU = TileMapCell.EID_OFF;
				}
			}
			else if (this.nU.ID == TileMapCell.TID_FULL)
			{
				this.eU = TileMapCell.EID_OFF;
			}
			else if (this.nU.ID == TileMapCell.TID_EMPTY)
			{
				this.eU = TileMapCell.EID_OFF;
			}
			else if ((((this.nU.signy * -1) <= 0) || (this.nU.ID == TileMapCell.TID_67DEGpnS)) || (this.nU.ID == TileMapCell.TID_67DEGnnS))
			{
				this.eU = TileMapCell.EID_INTERESTING;
			}
			else
			{
				this.eU = TileMapCell.EID_OFF;
			}
			// 下
			if (this.ID == TileMapCell.TID_EMPTY)
			{
				if (this.nD.ID == TileMapCell.TID_EMPTY)
				{
					this.eD = TileMapCell.EID_OFF;
				}
				else if (this.nD.ID == TileMapCell.TID_FULL)
				{
					this.eD = TileMapCell.EID_SOLID;
				}
				else if ((((this.nD.signy * 1) <= 0) || (this.nD.ID == TileMapCell.TID_67DEGppS)) || (this.nD.ID == TileMapCell.TID_67DEGnpS))
				{
					this.eD = TileMapCell.EID_INTERESTING;
				}
				else
				{
					this.eD = TileMapCell.EID_SOLID;
				}
			}
			else if (this.ID == TileMapCell.TID_FULL)
			{
				if (this.nD.ID == TileMapCell.TID_FULL)
				{
					this.eD = TileMapCell.EID_OFF;
				}
				else if (this.nD.ID == TileMapCell.TID_EMPTY)
				{
					this.eD = TileMapCell.EID_OFF;
				}
				else if ((((this.nD.signy * 1) <= 0) || (this.nD.ID == TileMapCell.TID_67DEGppS)) || (this.nD.ID == TileMapCell.TID_67DEGnpS))
				{
					this.eD = TileMapCell.EID_INTERESTING;
				}
				else
				{
					this.eD = TileMapCell.EID_OFF;
				}
			}
			else if (0 <= (this.signy * 1))
			{
				if (this.nD.ID == TileMapCell.TID_EMPTY)
				{
					this.eD = TileMapCell.EID_OFF;
				}
				else if (this.nD.ID == TileMapCell.TID_FULL)
				{
					this.eD = TileMapCell.EID_SOLID;
				}
				else if ((((this.nD.signy * 1) <= 0) || (this.nD.ID == TileMapCell.TID_67DEGppS)) || (this.nD.ID == TileMapCell.TID_67DEGnpS))
				{
					this.eD = TileMapCell.EID_INTERESTING;
				}
				else
				{
					this.eD = TileMapCell.EID_SOLID;
				}
			}
			else if ((this.ID == TileMapCell.TID_67DEGpnS) || (this.ID == TileMapCell.TID_67DEGnnS))
			{
				if (this.nD.ID == TileMapCell.TID_EMPTY)
				{
					this.eD = TileMapCell.EID_OFF;
				}
				else if (this.nD.ID == TileMapCell.TID_FULL)
				{
					this.eD = TileMapCell.EID_SOLID;
				}
				else if ((((this.nD.signy * 1) <= 0) || (this.nD.ID == TileMapCell.TID_67DEGppS)) || (this.nD.ID == TileMapCell.TID_67DEGnpS))
				{
					this.eD = TileMapCell.EID_INTERESTING;
				}
				else if ((0 < (this.nD.signy * 1)) || (this.nD.ID == TileMapCell.TID_FULL))
				{
					this.eD = TileMapCell.EID_SOLID;
				}
				else
				{
					this.eD = TileMapCell.EID_OFF;
				}
			}
			else if (this.nD.ID == TileMapCell.TID_FULL)
			{
				this.eD = TileMapCell.EID_OFF;
			}
			else if (this.nD.ID == TileMapCell.TID_EMPTY)
			{
				this.eD = TileMapCell.EID_OFF;
			}
			else if ((((this.nD.signy * 1) <= 0) || (this.nD.ID == TileMapCell.TID_67DEGppS)) || (this.nD.ID == TileMapCell.TID_67DEGnpS))
			{
				this.eD = TileMapCell.EID_INTERESTING;
			}
			else
			{
				this.eD = TileMapCell.EID_OFF;
			}
			// 右
			if (this.ID == TileMapCell.TID_EMPTY)
			{
				if (this.nR.ID == TileMapCell.TID_EMPTY)
				{
					this.eR = TileMapCell.EID_OFF;
				}
				else if (this.nR.ID == TileMapCell.TID_FULL)
				{
					this.eR = TileMapCell.EID_SOLID;
				}
				else if ((((this.nR.signx * 1) <= 0) || (this.nR.ID == TileMapCell.TID_22DEGpnS)) || (this.nR.ID == TileMapCell.TID_22DEGppS))
				{
					this.eR = TileMapCell.EID_INTERESTING;
				}
				else
				{
					this.eR = TileMapCell.EID_SOLID;
				}
			}
			else if (this.ID == TileMapCell.TID_FULL)
			{
				if (this.nR.ID == TileMapCell.TID_FULL)
				{
					this.eR = TileMapCell.EID_OFF;
				}
				else if (this.nR.ID == TileMapCell.TID_EMPTY)
				{
					this.eR = TileMapCell.EID_OFF;
				}
				else if ((((this.nR.signx * 1) <= 0) || (this.nR.ID == TileMapCell.TID_22DEGpnS)) || (this.nR.ID == TileMapCell.TID_22DEGppS))
				{
					this.eR = TileMapCell.EID_INTERESTING;
				}
				else
				{
					this.eR = TileMapCell.EID_OFF;
				}
			}
			else if (0 <= (this.signx * 1))
			{
				if (this.nR.ID == TileMapCell.TID_EMPTY)
				{
					this.eR = TileMapCell.EID_OFF;
				}
				else if (this.nR.ID == TileMapCell.TID_FULL)
				{
					this.eR = TileMapCell.EID_SOLID;
				}
				else if ((((this.nR.signx * 1) <= 0) || (this.nR.ID == TileMapCell.TID_22DEGpnS)) || (this.nR.ID == TileMapCell.TID_22DEGppS))
				{
					this.eR = TileMapCell.EID_INTERESTING;
				}
				else
				{
					this.eR = TileMapCell.EID_SOLID;
				}
			}
			else if ((this.ID == TileMapCell.TID_22DEGnnS) || (this.ID == TileMapCell.TID_22DEGnpS))
			{
				if (this.nR.ID == TileMapCell.TID_EMPTY)
				{
					this.eR = TileMapCell.EID_OFF;
				}
				else if (this.nR.ID == TileMapCell.TID_FULL)
				{
					this.eR = TileMapCell.EID_SOLID;
				}
				else if ((((this.nR.signx * 1) <= 0) || (this.nR.ID == TileMapCell.TID_22DEGpnS)) || (this.nR.ID == TileMapCell.TID_22DEGppS))
				{
					this.eR = TileMapCell.EID_INTERESTING;
				}
				else if ((this.nR.ID == TileMapCell.TID_FULL) || (0 < (this.nR.signx * 1)))
				{
					this.eR = TileMapCell.EID_SOLID;
				}
				else
				{
					this.eR = TileMapCell.EID_OFF;
				}
			}
			else if (this.nR.ID == TileMapCell.TID_FULL)
			{
				this.eR = TileMapCell.EID_OFF;
			}
			else if (this.nR.ID == TileMapCell.TID_EMPTY)
			{
				this.eR = TileMapCell.EID_OFF;
			}
			else if ((((this.nR.signx * 1) <= 0) || (this.nR.ID == TileMapCell.TID_22DEGpnS)) || (this.nR.ID == TileMapCell.TID_22DEGppS))
			{
				this.eR = TileMapCell.EID_INTERESTING;
			}
			else
			{
				this.eR = TileMapCell.EID_OFF;
			}
			// 左
			if (this.ID == TileMapCell.TID_EMPTY)
			{
				if (this.nL.ID == TileMapCell.TID_EMPTY)
				{
					this.eL = TileMapCell.EID_OFF;
				}
				else if (this.nL.ID == TileMapCell.TID_FULL)
				{
					this.eL = TileMapCell.EID_SOLID;
				}
				else if ((((this.nL.signx * -1) <= 0) || (this.nL.ID == TileMapCell.TID_22DEGnnS)) || (this.nL.ID == TileMapCell.TID_22DEGnpS))
				{
					this.eL = TileMapCell.EID_INTERESTING;
				}
				else
				{
					this.eL = TileMapCell.EID_SOLID;
				}
			}
			else if (this.ID == TileMapCell.TID_FULL)
			{
				if (this.nL.ID == TileMapCell.TID_FULL)
				{
					this.eL = TileMapCell.EID_OFF;
				}
				else if (this.nL.ID == TileMapCell.TID_EMPTY)
				{
					this.eL = TileMapCell.EID_OFF;
				}
				else if ((((this.nL.signx * -1) <= 0) || (this.nL.ID == TileMapCell.TID_22DEGnnS)) || (this.nL.ID == TileMapCell.TID_22DEGnpS))
				{
					this.eL = TileMapCell.EID_INTERESTING;
				}
				else
				{
					this.eL = TileMapCell.EID_OFF;
				}
			}
			else if (0 <= (this.signx * -1))
			{
				if (this.nL.ID == TileMapCell.TID_EMPTY)
				{
					this.eL = TileMapCell.EID_OFF;
				}
				else if (this.nL.ID == TileMapCell.TID_FULL)
				{
					this.eL = TileMapCell.EID_SOLID;
				}
				else if ((((this.nL.signx * -1) <= 0) || (this.nL.ID == TileMapCell.TID_22DEGnnS)) || (this.nL.ID == TileMapCell.TID_22DEGnpS))
				{
					this.eL = TileMapCell.EID_INTERESTING;
				}
				else
				{
					this.eL = TileMapCell.EID_SOLID;
				}
			}
			else if ((this.ID == TileMapCell.TID_22DEGpnS) || (this.ID == TileMapCell.TID_22DEGppS))
			{
				if (this.nL.ID == TileMapCell.TID_EMPTY)
				{
					this.eL = TileMapCell.EID_OFF;
				}
				else if (this.nL.ID == TileMapCell.TID_FULL)
				{
					this.eL = TileMapCell.EID_SOLID;
				}
				else if ((((this.nL.signx * -1) <= 0) || (this.nL.ID == TileMapCell.TID_22DEGnnS)) || (this.nL.ID == TileMapCell.TID_22DEGnpS))
				{
					this.eL = TileMapCell.EID_INTERESTING;
				}
				else if ((0 < (this.nL.signx * -1)) || (this.nL.ID == TileMapCell.TID_FULL))
				{
					this.eL = TileMapCell.EID_SOLID;
				}
				else
				{
					this.eL = TileMapCell.EID_OFF;
				}
			}
			else if (this.nL.ID == TileMapCell.TID_FULL)
			{
				this.eL = TileMapCell.EID_OFF;
			}
			else if (this.nL.ID == TileMapCell.TID_EMPTY)
			{
				this.eL = TileMapCell.EID_OFF;
			}
			else if ((((this.nL.signx * -1) <= 0) || (this.nL.ID == TileMapCell.TID_22DEGnnS)) || (this.nL.ID == TileMapCell.TID_22DEGnpS))
			{
				this.eL = TileMapCell.EID_INTERESTING;
			}
			else
			{
				this.eL = TileMapCell.EID_OFF;
			}
			this.Draw();
		}

		public function InsertObj(obj):void
		{
			obj.next = this.next;
			obj.prev = this;
			this.prev = null;
			if (this.next != null)
			{
				this.next.prev = obj;
			}
			this.next = obj;
			this.objcounter++;
		}

		public function RemoveObj(obj):void
		{
			obj.prev.next = obj.next;
			if (obj.next != null)
			{
				obj.next.prev = obj.prev;
			}
			obj.next = null;
			obj.prev = null;
			this.objcounter--;
		}
	}
}